/**
 * Project Name:fire-industry-DM-center
 * File Name:ConverterTerminal.java
 * Package Name:com.firestone.converters.center
 * Date:2018年3月30日下午1:55:54
 *
*/

package com.firestone.converters.center;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.baomidou.mybatisplus.plugins.Page;
import com.firestone.bean.dto.terminal.TerminalDTO;
import com.firestone.bean.vo.BaseListVO;
import com.firestone.bean.vo.terminal.TerminalVO;
import com.firestone.common.tool.DateUtils;
import com.firestone.core.constants.ConstantMapKey;

/**
 * @Description: TODO(终端菜单视图转换)
 * @author CAIYJ
 * @date 2018年3月30日 下午1:55:54
 */
public final class ConverterTerminal {

    /**
     * @Description: TODO(终端菜单列表视图转换)
     * @return
     * @author CAIYJ
     * @date 2018年3月30日 下午1:57:47
     * @lastModifier CAIYJ
     */
    public static final BaseListVO<TerminalVO> convertListVO(
            Page<TerminalDTO> page) {
        BaseListVO<TerminalVO> base = new BaseListVO<TerminalVO>();
        if (page != null) {
            if (page.getRecords() != null && page.getRecords().size() > 0) {
                List<TerminalVO> list = new ArrayList<>();
                for (TerminalDTO dto : page.getRecords()) {
                    TerminalVO vo = new TerminalVO();
                    BeanUtils.copyProperties(dto, vo);
                    if (dto.getCreateTime() != null) {
                        vo.setCreateTime(
                                DateUtils.getTimeStampStr(dto.getCreateTime()));
                    }
                    if (dto.getUpdateTime() != null) {
                        vo.setUpdateTime(
                                DateUtils.getTimeStampStr(dto.getUpdateTime()));
                    }
                    vo.setIsDelete(
                            ConstantMapKey.IS_DELETE.get(dto.getIsDelete()));
                    list.add(vo);
                }
                base.setList(list);
            }
            base.setCount(page.getTotal());
        }
        return base;
    }
}
